package com.caltco.cargo.ops.modules.sys.controller;

import com.caltco.cargo.ops.common.api.R2;
import com.caltco.cargo.ops.common.api.Result;
import com.caltco.cargo.ops.modules.sys.request.StatisticsTimeRequest;
import com.caltco.cargo.ops.modules.sys.service.DailyStatisticsService;
import com.caltco.cargo.ops.modules.sys.vo.DailyStatisticsByModelVO;
import com.caltco.cargo.ops.modules.sys.vo.DailyStatisticsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("DailyStatistics")
@RequestMapping("/api/daily/statistics")
public class DailyStatisticsController {
    private final DailyStatisticsService dailyStatisticsService;

    public DailyStatisticsController(DailyStatisticsService dailyStatisticsService) {
        this.dailyStatisticsService = dailyStatisticsService;
    }

    @GetMapping("list")
    public Result<List<DailyStatisticsVO>> getDailyStatistics(){
        return R2.ok(dailyStatisticsService.getDailyStatistics());
    }

    @GetMapping("getByDay")
    public Result<DailyStatisticsVO> getDailyStatisticsByDay(){
        return R2.ok(dailyStatisticsService.getDailyStatisticsByDay());
    }

    @GetMapping("getStatisticsByModel")
    public Result<DailyStatisticsByModelVO> DailyStatisticsByModel(@RequestParam("model") Integer model){
        return R2.ok(dailyStatisticsService.DailyStatisticsByModelVO(model));
    }

    @GetMapping("getByYesterday")
    public Result<DailyStatisticsVO> getDailyStatisticsByYesterday(){
        return R2.ok(dailyStatisticsService.getDailyStatisticsByYesterday());
    }

    @PostMapping("statisticsTime")
    public Result<String> statisticsTime(@RequestBody StatisticsTimeRequest request){
        return dailyStatisticsService.statisticsTime(request)?R2.ok("新增成功"):R2.err("新增失败");
    }
}
